Git Commit Message Conventions
I want to take a moment to elaborate on what makes a well formed commit message. I think the best practices for commit message formatting is one of the little details that makes Git great.
Goals
Good commit messages should satisfy the below goals.
- allow generating CHANGELOG.md by script
- allow ignoring commits by git bisect (not important commits like formatting)
- provide better information when browsing the history
Generating CHANGELOG.md
We use these three sections in changelog: new features, bug fixes, breaking changes.
This list could be generated by script when doing a release. Along with links to related commits.
Of course you can edit this change log before actual release, but it could generate the skeleton.
List of all subjects (first lines in commit message) since last release:>> git log <last tag> HEAD --pretty=format:%s
New features in this release>> git log <last release> HEAD --grep FEAT
Recognizing unimportant commits
These are formatting changes (adding/removing spaces/empty lines, indentation), missing semi colons, comments. So when you are looking for some change, you can ignore these commits - no logic change inside this commit.
When bisecting, you can ignore these by:>> git bisect skip $(git rev-list --grep irrelevant <good place> HEAD)
Provide more information when browsing the history
This would add kinda “context” information.
Look at these messages (taken from last few angular’s commits):
All of these messages try to specify where is the change. But they don’t share any convention…
Look at these messages:
Are you able to guess what’s inside ? These messages miss place specification…
So maybe something like parts of the code: docs, docs-parser, compiler, scenario-runner, …
I know, you can find this information by checking which files had been changed, but that’s slow. And when looking in git history I can see all of us tries to specify the place, only missing the convention.
Format of the commit message
|
|
Any line of the commit message cannot be longer 72 characters! This allows the message to be easier to read on github as well as in various git tools.
Subject line
Subject line contains succinct description of the change.
Allowed
- feet (feature)
- fix (bug fix)
- docs (documentation)
- style (formatting, missing semi colons, …)
- refactor (refactoring)
- test (when adding missing tests)
- chore (maintain)
Allowed
Scope could be anything specifying place of the commit change. For example $location, $browser, $compile, $rootScope, ngHref, ngClick, ngView, etc…
text
Subject should use imperative, present tense: “change” not “changed” nor “changes”
don’t capitalize first letter
no dot (.) at the end
Message body
just as in
by commands like git merge and git revert.
More detailed explanatory text, if necessary. Wrap it to about 72 characters or so.
The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, followed by a single space, with blank lines in between, but conventions vary here
- Use a hanging indent
Message footer
Referencing issues
Closed bugs should be listed on a separate line in the footer prefixed with “Closes” keyword like this:
Closes #234
or in case of multiple issues:
Closes #123, #245, #992
Breaking changes
All breaking changes have to be mentioned in footer with the description of the change, justification and migration notes
Examples
|
|
|
|
|
|
|
|
|
|